/**
 * 加载提示框
 * @class Loading
 * @constructor
 */
class Loading {
	
	static #DISPLAY_BLOCK = 'block';
	static #DISPLAY_NONE = 'none';
	static DEFAULT_MESSAGE = '加载中......';
	static LOADING = 'loading';
	static LOADED = 'loaded';
	
	/**
	 * @param {string} root 提示框元素选择器
	 * @param {string} content 文本元素选择器
	 *
	 * @property {string} state 是否正在加载中
	 */
	constructor(selector = '.loading', content) {
		this.state = Loading.LOADED;
		this.root = document.querySelector(selector);
		if (content) {
			this.content = this.root.querySelector(content);
			return;
		} 
		this.content = this.root;
	}
	
	/**
	 * 加载中
	 * @param {string} 提示信息
	 */
	loading() {
		this.state = Loading.LOADING;
		this.root.style.display = Loading.#DISPLAY_BLOCK;
	}
	
	/**
	 * 加载完毕
	 */
	loaded() {
		this.state = Loading.LOADED;
		this.root.style.display = Loading.#DISPLAY_NONE;
	}
	
	/**
	 * 展示信息
	 * @param {string} message 要展示的信息
	 */
	show(message) {
		this.content.textContent = message;
		this.root.style.display = Loading.#DISPLAY_BLOCK;
	}
	
	/**
	 * 隐藏提示框
	 */
	hide() {
		this.root.style.display = Loading.#DISPLAY_NONE;
		this.content.textContent = '';
	}
}